<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择往来单位信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>


<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3 layui-col-xs12 layui-col-sm6">
                        <label class="layui-form-label">单位名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">所属分类</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <div id="type" class="xmselect_div">-->
<!--                                <div class="xmselect_title">请选择</div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-col-md3 layui-col-xs6">
                        <label class="layui-form-label">单位性质</label>
                        <div class="layui-input-block">
                            <div id="nature" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 layui-col-xs6">
                        <label class="layui-form-label">法人代表</label>
                        <div class="layui-input-block">
                            <input type="text" name="legaler" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">注册地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhuaddr" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">税务类型</label>
                        <div class="layui-input-block">
                            <div id="taxtype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">税号</label>
                        <div class="layui-input-block">
                            <input type="text" name="ratenum" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">单位地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="unitaddr" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">电话号码</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="phone" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">开户银行</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="bankname" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">银行账号</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="banknum" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">经营类别</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="genre" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">单位评级</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <div id="danlevel"></div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">联系人</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="lianer" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">联系人手机号</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="liantel" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-col-md3 layui-col-xs6">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="type" name="type">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <?php include '../dealcom/dao.php' ?>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_add_flow('新建')">
            <i class="layui-icon layui-icon-add-1"></i>新建
        </button>
    </div>
</script>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }

    var parent_dom = getQueryVariable('dom');
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_dealcom),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){

                // xmselect_dan('type', res.data.type, res.data.is_type, function (res) {
                //     setTimeout(function () {
                //         searchTableFunc(form, table);
                //     },100)
                // })
                xmselect_dan('taxtype', res.data.taxtype, res.data.is_taxtype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })
                xmselect_dan('nature', res.data.nature, res.data.is_nature, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })
                xmselect_dan('danlevel', res.data.danlevel, res.data.is_danlevel, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })


                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type,fixed:'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'name', title: '单位名称'}
                ,{field: 'type', title: '所属分类'}
                ,{field: 'nature', title: '单位性质'}
                ,{field: 'legaler', title: '法人代表'}
                ,{field: 'zhuaddr', title: '注册地址'}
                ,{field: 'taxtype', title: '税务类型'}
                ,{field: 'ratenum', title: '税号'}
                ,{field: 'unitaddr', title: '单位地址'}
                // ,{field: 'phone', title: '电话号码'}
                // ,{field: 'bankname', title: '开户银行'}
                // ,{field: 'banknum', title: '银行账号'}
                // ,{field: 'genre', title: '经营类别'}
                // ,{field: 'danlevel', title: '单位评级'}
                // ,{field: 'lianer', title: '联系人'}
                // ,{field: 'liantel', title: '联系人手机号'}
            ]]
            ,done : function(res, curr, count){
                // $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == 'user'){
                var str = '';
                for(var key in data){
                    str += '<button type="button" style="width: auto;" class="layui-btn layui-btn-sm btn-dark" key="'+data[key].id+'"><span class="choose_content">'+data[key].name+'' +
                        '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                }
                $("#"+parent_dom , parent.document).append(str);
                var h = $("#"+parent_dom , parent.document).height();
                $("."+parent_dom , parent.document).css('cssText','height:'+ (h+5) +'px !important');

                parent.formValid(parent_dom);

            }else if(parent_page == 'bid'){
                var str = '';
                for(var key in data){
                    str += '<button type="button" style="width: auto;max-width: 95%;" class="layui-btn layui-btn-sm btn-dark" key="'+data[key].id+'"><span class="choose_content">'+data[key].name+'' +
                        '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                }
                $("#"+parent_dom , parent.document).html(str);
                var h = $("#"+parent_dom , parent.document).height();
                $("."+parent_dom , parent.document).css('cssText','height:'+ (h+5) +'px !important');

                parent.formValid(parent_dom);
            } else if(parent_page == 'piao_shou'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.gonger').val(data[0].name);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'dealcom_geng'){
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].name+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);

                $("#name" , parent.document).val(data[0].name);
                $("#legaler" , parent.document).val(data[0].legaler);
                $("#zhuaddr" , parent.document).val(data[0].zhuaddr);
                $("#taxtype" , parent.document).val(data[0].taxtype);
                $("#piaotype" , parent.document).val(data[0].piaotype);
                $("#rate" , parent.document).val(data[0].rate);
                $("#ratenum" , parent.document).val(data[0].ratenum);
                $("#unitaddr" , parent.document).val(data[0].unitaddr);
                $("#phone" , parent.document).val(data[0].phone);
                $("#bankname" , parent.document).val(data[0].bankname);
                $("#banknum" , parent.document).val(data[0].banknum);
                $("#genre" , parent.document).val(data[0].genre);
                $("#lianer" , parent.document).val(data[0].lianer);
                $("#liantel" , parent.document).val(data[0].liantel);
                $("#explain" , parent.document).val(data[0].explain);

                window.parent.set_type(data[0].type_old);
                window.parent.set_nature(data[0].nature_old);
                window.parent.set_taxtype(data[0].taxtype_old);
                window.parent.set_danlevel(data[0].danlevel_old);
                window.parent.set_piaotype(data[0].piaotype_old);
                window.parent.public_upload_file_load('upload_files', data[0].files);

            }else{
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].name+'"><span class="choose_content">'+data[0].name+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);

                if(parent_page == 'contract_nei'){
                    $("#dutytel" , parent.document).val(data[0].liantel);
                }

                if(parent_page == 'contract_shi'){
                    $("#fauser" , parent.document).val(data[0].lianer);
                    $("#fatel" , parent.document).val(data[0].liantel);
                }

                if(parent_page == 'contract_cai'){
                    $("#gonguser" , parent.document).val(data[0].lianer);
                    $("#gongtel" , parent.document).val(data[0].liantel);
                }

                if(parent_page == 'contract_ling'){
                    $("#gongtel" , parent.document).val(data[0].liantel);
                }

                if(parent_page == 'piao_kai'){
                    $("#ratenum" , parent.document).val(data[0].ratenum);
                    $("#bankname" , parent.document).val(data[0].bankname);
                    $("#banknum" , parent.document).val(data[0].banknum);
                    $("#unitaddr" , parent.document).val(data[0].unitaddr);
                    $("#phone" , parent.document).val(data[0].phone);
                }

                if(parent_page == 'payment_day'){
                    $("#bankname" , parent.document).val(data[0].bankname);
                    $("#banknum" , parent.document).val(data[0].banknum);
                }
                if(parent_page == 'payment_neifu'){
                    $("#bankname" , parent.document).val(data[0].bankname);
                    $("#banknum" , parent.document).val(data[0].banknum);
                }

                if(parent_page == 'engin_bond_jiao'){
                    $("#bankname" , parent.document).val(data[0].bankname);
                    $("#banknum" , parent.document).val(data[0].banknum);
                }
                if(parent_page == 'engin_bond_fan'){
                    $("#bankname" , parent.document).val(data[0].bankname);
                    $("#banknum" , parent.document).val(data[0].banknum);
                }
                if(parent_page == 'stuff_jie'){
                    $("#caiid", parent.document).html('');
                    $("#jie_list", parent.document).html('');
                }
            }

            layer_close();
        });




    });



    function auth_but_func_add_flow(){
        openPageEdit('../dealcom/flow_add.php?close=1');
    }
</script>
</body>
</html>
